import myAxios from "../plugins/myAxios";
import { setCurrentUserState} from "../states/user";
import {useRouter} from "vue-router";
export const getCurrentUser = async () => {
    // const currentUser = getCurrentUserState();
    // if (currentUser) {
    //     return currentUser;
    // }
    // 不存在则从远程获取
    const router = useRouter();
    const res:any = await myAxios.get('/user/current');
    if (res?.code === 0) {
        setCurrentUserState(res.data);
        return res.data;
    }else {
        router.push('/user/login');
    }
}


export const logout = async () => {
    const res:any = await myAxios.post('/user/logout');
    if (res?.code === 0) {
        return res.data;
    }
    return null;
}
